// packageJ/consensus_activity/withdraw/withdraw.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    text: "",
    count: 0,
    type: null, //1-元积分、2-元积分提现配额、3-收益积分、4-原资产

    income: "",
    uid: "",
    income_to_yuan_fee_rate: "",
    income_name: "",
    yuan_name: "",
    yuan_withdraw_limit_name: "",
    yuan_withdraw_quota: 0,
    usable_yuan: 0,
    open:1,//是否扣除提现配置
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let type = Number(options.num);
    if(options.open){
      this.setData({open:options.open});
    }
    this.setData({type});
    this.getData();
  },
  getData() {
    let urlStr = "";
    if (this.data.type == 1 || this.data.type == 2|| this.data.type==5) {
      urlStr = 'plugin.wise-yuan-trade.frontend.yuan-point.index';
    } else if (this.data.type == 3|| this.data.type==4 || this.data.type==6) {
      urlStr = 'plugin.wise-yuan-trade.frontend.income-point.index';
    }
    app._getNetWork({
      url: app.getNetAddresss(urlStr),
      success: resdata => {
        let { result,data, msg} = resdata.data;
        if (result) {
          if (this.data.type == 1 || this.data.type == 2 || this.data.type==5) {
            if (this.data.type == 1||this.data.type==5) {
              this.setData({
                yuan_name: data.yuan_name,
                yuan_withdraw_limit_name: data.yuan_withdraw_limit_name,
                yuan_withdraw_quota: data.yuan_withdraw_quota,
                usable_yuan: data.usable_yuan,
              })
              if(this.data.type == 1){
                wx.setNavigationBarTitle({title:`${data.yuan_name}提现`})
              }else{
                app._getNetWork({
                  url:app.getNetAddresss("plugin.wise-yuan-trade.frontend.income-point.index"),
                  success:_resdata=>{
                    let _data = _resdata.data;
                    if(_data.result!==1){
                      return app.tips(_data.msg);
                    }
                    wx.setNavigationBarTitle({title: `转入${_data.data.income_name}`})
                  }
                })
              }

            } else {
              this.setData({
                yuan_withdraw_quota: data.yuan_withdraw_quota,
                yuan_withdraw_limit_name: data.yuan_withdraw_limit_name,
              })
              wx.setNavigationBarTitle({
                title: '会员转让',
              })
            }
          } else {
            let text = '';
            this.setData({
              income: data.income,
              income_name: data.income_name,
              income_to_yuan_fee_rate: data.income_to_yuan_fee_rate
            })
            if(this.data.type==6){
              text = `${data.income_name}提现`;
            }else if(this.data.type==4){
              text="会员转让";
              this.setData({  income_to_yuan_fee_rate : data.income_mutual_transfer_fee_rate||0})
            }else{
              text = `转入${data.yuan_name}`;
            }
            wx.setNavigationBarTitle({title: text})
            this.setData({  income_name : data.income_name})
          }
        } else {
          app.tips(msg);
        }
      }
    })
  },
  onInput(e){
    let type = e.currentTarget.dataset.type;
    let value = e.detail.value;
    if(type=="1"){
      this.setData({uid:value})
    }else if(type=="2"){
      this.setData({count:value})
    }
  },
  focus(e){
    let value = Number(e.detail.value);
    if(value==0 ){
      this.setData({count:''})
    }
  },
  all_handle() {
    if (this.data.type == 1||this.data.type==5) {
      this.setData({count:this.data.usable_yuan})
    }else if(this.data.type ==2){
      this.setData({count:this.data.yuan_withdraw_quota})
    }else{
      this.setData({count:this.data.income})
    }
  },

  confirm(){
    let urlStr = "", json = {amount: this.data.count};
    if (this.data.type == 1) {
      urlStr = 'plugin.wise-yuan-trade.frontend.yuan-point.withdraw';
    } else if (this.data.type == 2) {
      urlStr = 'plugin.wise-yuan-trade.frontend.yuan-point.yuan-quota-transfer';
      json.uid=this.data.uid;
    }else if(this.data.type==4){
      urlStr = 'plugin.wise-yuan-trade.frontend.income-point.mutual-transfer';
      json.uid= this.data.uid;
    }else if(this.data.type==5){
      urlStr="plugin.wise-yuan-trade.frontend.yuan-point.yuan-to-income";
    }else if(this.data.type==6){
      urlStr="plugin.wise-yuan-trade.frontend.income-point.withdraw";
    } else {
      urlStr = 'plugin.wise-yuan-trade.frontend.income-point.to-yuan';
    }
    app._postNetWork({
      url:app.getNetAddresss(urlStr),
      data:json,
      success:resdata=>{
        let {result,msg} = resdata.data;
        app.tips(msg);
        if (result) {
          this.setData({count:0})
          this.getData();
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})